package com.hlw.hr_man.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.hlw.hr_man.Model.EmployeeModel;
import com.hlw.hr_man.service.UpdateCardService;
import com.hlw.hr_man.serviceImpl.UpdateCardServiceImpl;

public class UpdateCardcontroller extends HttpServlet {
	UpdateCardService ucs = new UpdateCardServiceImpl();

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		req.setCharacterEncoding("utf8");
		resp.setCharacterEncoding("utf8");
		PrintWriter pw = resp.getWriter();
		HttpSession session = req.getSession();
		String card_company = req.getParameter("card_company");
		String card_address = req.getParameter("card_address");
		String card_tel = req.getParameter("card_tel");
		String card_email = req.getParameter("card_email");
		int e_id = (int) session.getAttribute("employeeid");
		EmployeeModel employee = new EmployeeModel(e_id, card_company,
				card_address, card_tel, card_email);
		if (ucs.isHaveCard(e_id) == true) {
			int flag = ucs.updataStudent(employee);
			pw.write(String.valueOf(flag));
		} else {
			pw.write("-1");
		}
	}
}
